
$(function() {
});

var Job = {
	dialog_add_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_add').dialog('option', 'buttons', {
			"关闭": function() {
				$(this).dialog("close");
			},

			"添加": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
				
				var form = $("#form_add")[0];

				var body = { };
				body.name = form.name.value;
				body.type = form.type.value;
				body.num = form.num.value;
				
				body.sex = form.sex.value;
				body.age = form.age.value;
				body.education = form.education.value;
				body.pay = form.pay.value;
				
				body.address = form.address.value;
				body.work = form.work.value;
				body.content = form.content.value;
				body.expired = form.expired.value;

				$(this).dialog("close");

				$.post('info.php?do=Job.addPost', body, function(data) {
					$(result).html(data);
				});
			}
		});

		dialog_add(url, title, xy);
	},	

	popup: function (e, p2, id, status) {
		$.cookie('id_', id);

		$.cookie('status_', status);
		
		p2 = query(p2);
		$.cookie('p2', p2);
		
		var c1 = 'info.php?do=Job.edit&id=' + id;	
		var c2 = 'info.php?do=Job.view&id=' + id;
		
		var c6 = 'info.php?do=Job.emp&id=' + id;

		var a1 = ['编辑信息', 'url', 'Job.dialog_edit_', '600x400'];
		var a2 = ['查看信息', 'url', 'Common.dialog_view_', '600x400'];
		
		var a6 = ['应聘人员', 'url', 'Job.dialog_emp_', '600x400'];
		
		var s = c1 + ", " + c2 + ", " + c6;

		return this.popup_(e, [a1, a2, a6], s);		
	},
	
	popup_: function (e, a, s) {
		var id = $.cookie('id_');
		
		var ss = 'info.php?do=Job.ss&id=' + id;
		var bb = ['修改状态', 'url', 'Job.dialog_ss', '400x200', '修改状态'];
		
		s += ", " + ss;
		a.push(bb);
		
		return popup(e, a, s);
	},
	
	dialog_ss: function (url, title, xy) {
		result = Common.result();
		$.getJSON('info.php?do=Job.ajax_oper', function(json) {
			if (json.status == 1) {
				$('#dialog_edit').dialog('option', 'buttons', {
					"关闭": function() {
						$(this).dialog("close");
					},

					"修改": function() {
						if (!confirm("确认是否提交？")) {
							return false;
						}

						var form = $("#form_edit")[0];

						var body = {};
						body.id = form.id.value;
						body.field = form.field.value;
						body.data = form.data.value;
						body.status = form.status.value;

						$(this).dialog("close");

						var url = 'info.php?do=Job.ssPost';
						var p2 = $.cookie('p2');
						if (p2 != null) {
							url += p2;
						}

						$.post(url, body, function(data) {
							$(result).html(data);
						});
					}
				});

				dialog_edit(url, title, xy);
			} else {
				_error();
			}
		});
	},

	dialog_edit_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_edit').dialog('option', 'buttons', {
			"关闭": function() { 
				$(this).dialog("close");
			},
			
			"修改": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
				
				var form = $("#form_edit")[0];
				
				var body = {};
				body.id = form.id.value;
				body.name = form.name.value;
				body.type = form.type.value;
				body.num = form.num.value;
				
				body.sex = form.sex.value;
				body.age = form.age.value;
				body.education = form.education.value;
				body.pay = form.pay.value;
				
				body.address = form.address.value;
				body.work = form.work.value;
				body.content = form.content.value;
				body.expired = form.expired.value;
				body.orderby = form.orderby.value;
				
				body.emp = form.emp.value;

				$(this).dialog("close");

				var url = 'info.php?do=Job.editPost';
				var p2 = $.cookie('p2');
				if (p2 != null) {
					url += p2;
				}

				$.post(url, body, function(data) {
					$(result).html(data);
				});
			}
		});

		dialog_edit(url, title, xy);
	},
	
	dialog_emp_: function (url, title, xy) {
		var result = Common.result();
		$('#dialog_add').dialog('option', 'buttons', {
			"关闭": function() {
				$(this).dialog("close");
			},

			"添加": function() {
				if (!confirm("确认是否提交？")) {
					return false;
				}
				
				var form = $("#form_add")[0];

				var body = { };
				body.job = form.job.value;
				
				body.name = form.name.value;				
				body.idcard = form.idcard.value;
				
				body.password = form.password.value;
				body.sex = form.sex.value;
				body.birthday = form.birthday.value;
				
				body.province = form.province.value;
				body.city = form.city.value;
				body.district = form.district.value;
	
				body.address = form.address.value;
				
				body.content = form.content.value;

				$(this).dialog("close");

				$.post('info.php?do=Job.empPost', body, function(data) {
					$(result).html(data);
				});
			}
		});

		dialog_add(url, title, xy);
	}
};
